package com.afd.ozblip.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.afd.ozblip.activity.R;
import com.afd.ozblip.entity.DishEntity;
import com.afd.ozblip.entity.RecDishEntity;
import com.afd.ozblip.helper.DishVH;
import com.afd.ozblip.helper.RecDishVH;
import com.afd.ozblip.util.CollectionUtil;
import com.afd.ozblip.util.StringUtil;


public class RecDishListAdapter extends BaseAdapter {

	public List<RecDishEntity> dataList;
	private LayoutInflater inflater;
	private Context context;

	public RecDishListAdapter(Context paramContext) {
		context = paramContext;
		this.dataList = new ArrayList<RecDishEntity>();
		this.inflater = LayoutInflater.from(context);
	}

	/**
	 *获取列表条数
	 */
	@Override
	public int getCount() {
		if (CollectionUtil.UnNullAndZero(this.dataList)) {
			return this.dataList.size();
		} else {
			return 0;
		}

	}

	@Override
	public Object getItem(int paramInt) {
		if (CollectionUtil.UnNullAndZero(this.dataList)) {
			return this.dataList.get(paramInt);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int paramInt) {
		return paramInt;
	}

	@Override
	public View getView(int position, View paramView, ViewGroup paramViewGroup) {
		try {
			RecDishVH dishVH = null;
			if (paramView == null) {
				dishVH = new RecDishVH();
				paramView = this.inflater.inflate(R.layout.recommend_dish_item,
						null);
				
				dishVH.recDishNameTv = (TextView) paramView
						.findViewById(R.id.tv_business_recommend_list_item_dishName);
				dishVH.recNumsTv = (TextView) paramView
						.findViewById(R.id.tv_business_recommend_list_item_recNums);
				paramView.setTag(dishVH);
			} else {
				dishVH = (RecDishVH) paramView.getTag();
			}
			
			RecDishEntity dish = this.dataList.get(position);
			if (dish != null) {
				// 菜名
				String dishName = dish.getDishName();
				if (!StringUtil.isNullOrEmpty(dishName)) {
					dishVH.recDishNameTv.setText(dishName);
				}
				Integer recNums = dish.getRecNums();
				if (!StringUtil.isNullOrZero(recNums)) {
					dishVH.recNumsTv.setText(String.valueOf(recNums));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return paramView;
	}

	/**
	 * 添加多项
	 */
	public void addItems(List<RecDishEntity> commentList) {
		this.dataList.addAll(commentList);
	}

	/**
	 * 清除所有项
	 */
	public void removeAllItem() {
		this.dataList.clear();
	}
}

